define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, $rootScope, T_set, GoPage, GoDialog, Auth, $ionicHistory, $cacheFactory, ChatInfo, GoHotCode, FileSystem) {

		$scope.$on('$ionicView.beforeEnter', function() {
			$scope.check = Auth.check_user_type();
			var Infos = Auth.get_loginInfo();
			$scope.issue_type = Infos.issue_type;//1买家    2卖家
		}, false);
		//画面加载
		$scope.$on('$ionicView.afterEnter', function() {
			//动态设置高度
			 GoPage.init_top($scope, 44);
		}, false);
		//促销
		$scope.onshow_setting = function(url) {
			if(url == 'pay-password') {
				GoPage.go_states(url, { "order_id": "" });
			} else {
				GoPage.go_states(url);
			}
		};
		
		//检查更新
		$scope.check_update = function(url) {
			//代码提示
			GoHotCode.checkUpdate();
		};
		$scope.clear_storage = function() {
			//包含删除所有文件
			FileSystem.deleteFileSystemRoot([]);
			$ionicHistory.clearCache();
			GoDialog.toast("缓存清除成功！");
		}
		//退出
		$scope.onshow_exit = function() {
			GoDialog.confirm('确认', '确定要退出登录？', function() {
				T_set.logout(function(data){
					if(data.success){
						//删除登录信息
						Auth.clear_loginInfo();
						ChatInfo.clear_chatInfo();
						//返回
						GoPage.go_back(-1);
						//注册了全局广播
						$rootScope.$broadcast('acountLoginOutEvent');
						$rootScope.wlwj_user_auth = ""; //清空权限数据
						$rootScope.isShowRedBag = false;//一注销，就立刻不显示红包
					}else{
						GoDialog.alert("提示",data.msg);
					}
				})
			});
		};
		
		//注册了全局广播
		$rootScope.$on('editSettingEvent', function(event, data) {
			$scope.check = Auth.check_user_type();
		});
		//打开客服
		$scope.opencustemOK = function() {
			GoPage.go_tolive800();
		};
	}

	controller.$inject = ['$scope', '$rootScope', 'T_set', 'GoPage', 'GoDialog', 'Auth', '$ionicHistory', '$cacheFactory', 'ChatInfo', 'GoHotCode', 'FileSystem'];

	return app.registerController("t_setctrl", controller);
});